import wx

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Modifing Hopping Sequency Console", style = wx.DEFAULT_FRAME_STYLE)
        
        self.submit = wx.Button(self, -1, "Press to Modify")
        self.send = wx.Button(self, -1, "Press to Restore")
        #self.autosend = wx.Button(self, -1, "Auto Send")
        self.outputLabel = wx.StaticText(self, -1, "The New AFH_MAP Value: ")
        self.output = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
        self.inputLabel = wx.StaticText(self, -1, "The CC Bluetooth Module: ")
        self.input = wx.TextCtrl(self, -1, size=(125, -1))
        #self.scan = Scan()
        self.timer = wx.Timer(self)
        #self.timer.Start(100)
        
        self.__make_menu()
        self.__do_layout()
        self.__attach_event()  
	
    def __make_menu(self):
		#-- File Menu 
        FileMenu = wx.Menu()
        Open = FileMenu.Append(-1, "&Open\tCtrl-O")
        FileMenu.AppendSeparator()
        exit = FileMenu.Append(-1, "E&xit\tCtrl-Q")
        #self.Bind(wx.EVT_MENU, self.OnExit, exit)
        
        #-- Edit Menu
        EditMenu = wx.Menu()
        Undo = EditMenu.Append(-1, "&Undo\tCtrl-Z")
        EditMenu.AppendSeparator()
        Cut = EditMenu.Append(-1, "Cu&t\tCtrl-X")
        Copy = EditMenu.Append(-1, "&Copy\tCtrl-C")
        Paste = EditMenu.Append(-1, "&Paste\tCtrl-V")
        
        #-- Help Menu
        HelpMenu = wx.Menu()
        About = HelpMenu.Append(-1, "&About")
        HelpMenu.AppendSeparator()
        GPCHelp = HelpMenu.Append(-1, "&GPC Help\tF1")
        
        ## Append menu in MenuBar
        menuBar = wx.MenuBar()
        menuBar.Append(FileMenu, "&File")
        menuBar.Append(EditMenu, "&Edit")
        menuBar.Append(HelpMenu, "&Help")
        
        self.SetMenuBar(menuBar)        
        
    def __do_layout(self):
        self.SetMaxSize((700, 800))		
        self.output.SetMinSize((220, 50))
        
        sizer_v_output = wx.BoxSizer(wx.VERTICAL)
        sizer_v_output.Add(self.outputLabel, 0, wx.ALL, 5)
        sizer_v_output.Add(self.output, 0, wx.ALL, 5)
        sizer_v_output.Add(self.inputLabel, 0, wx.ALL, 5)
        sizer_v_output.Add(self.input, 0, wx.ALL, 5)
        sizer_h_submit = wx.BoxSizer(wx.HORIZONTAL)
        sizer_h_submit.Add(self.submit, 0, wx.ALL, 5)
        sizer_h_submit.Add(self.send, 0, wx.ALL, 5)
        #sizer_h_submit.Add(self.autosend, 0, wx.ALL, 5)
        sizer_v_output.Add(sizer_h_submit, wx.ALL, 5)
        
        sizer_h = wx.BoxSizer(wx.HORIZONTAL)
        sizer_h.Add(sizer_v_output, 0, wx.ALL, 5)
        
        sizer_v = wx.BoxSizer(wx.VERTICAL)
        sizer_v.Add(sizer_h, 0, wx.ALL | wx.EXPAND, 0)
		
        self.SetAutoLayout(1)
        self.SetSizer(sizer_v)
        sizer_v.Fit(self)
        sizer_v.SetSizeHints(self)
        self.Layout()
		
    def __attach_event(self):
        self.submit.Bind(wx.EVT_BUTTON, self.OnSubmit)
        self.send.Bind(wx.EVT_BUTTON, self.OnSend)
        #self.autosend.Bind(wx.EVT_BUTTON, self.OnAutoSend)
        self.Bind(wx.EVT_TIMER, self.TimerHandler)
        #self.showGraph.Bind(wx.EVT_BUTTON, self.OnShowGraph)
   
    def OnSubmit(self, event):
        print 'Change the AFH_MAP parameter for Bluetooth'
        
    def OnSend(self, event):
        print 'Restore the AFH_MAP parameter as before'
        
    def OnAutoSend(self, evnet):
        #self.TimerHandler()
        self.timer.Start(3000)
        
    def TimerHandler(self, event):
        self.scan.Send()
        print 'send the mac-rssi pair successfully'
        
if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MainFrame()
    frame.Show()
    app.MainLoop()